#!/usr/local/bin/php
<?php
defined('OPEN_LIB_PATH') || define('OPEN_LIB_PATH', '/opt/op/OpenLib');

require_once OPEN_LIB_PATH . '/open/business-logic/OaAppLogic.php';

$logger = Log::factory('console', '', '', array(
    'lineFormat' => '[%1$s] [%3$s] %5$s(%6$s): %4$s',
    'timeFormat' => '%Y-%m-%d %H:%M:%S'
), PEAR_LOG_INFO);
$options = getopt('g:c:');
if (empty($options)) {
    $logger->err("usage: " . basename(__FILE__) . " -g app_id -c company_id");
    exit();
}
if (!isset($options['g'])) {
    $logger->err("no app id");
    exit();
}
$appId = (int) $options['g'];
if (!isset($options['c'])) {
    $logger->err("no new company id");
    exit();
}
$newCompanyId = (int) $options['c'];

if (!OaAppLogic::moveAppToAnotherCompany($appId, $newCompanyId)) {
    $logger->err("move failed: app-$appId, company-$newCompanyId");
} else {
    $logger->info("move succeed: app-$appId, company-$newCompanyId");
}